package com.symc.his.api.impl.drug;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.symc.his.api.base.BaseApiService;
import com.symc.his.api.base.BaseResponse;
import com.symc.his.api.drug.DrugInventoryService;
import com.symc.his.api.drug.dto.resp.DrugInventoryRespDTO;
import com.symc.his.api.impl.entity.DrugInventoryDO;
import com.symc.his.api.impl.mapper.DrugInventoryMapper;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author forward
 */
@RestController
public class DrugInventoryServiceImpl extends BaseApiService implements DrugInventoryService {
    @Resource
    private DrugInventoryMapper drugInventoryMapper;

    @Override public BaseResponse<DrugInventoryRespDTO> getDrugInventoryListByLikeDrugName(String drugName) {
        LambdaQueryWrapper<DrugInventoryDO> queryWrapper = new LambdaQueryWrapper<DrugInventoryDO>()
            .like(!StringUtils.isEmpty(drugName), DrugInventoryDO::getDrugName, drugName)
            .gt(DrugInventoryDO::getStockQuantity,0);
        List<DrugInventoryDO> dos = drugInventoryMapper.selectList(queryWrapper);
        List<DrugInventoryRespDTO> inventoryRespDTOList = dos.stream().map(e -> DO2DTO(e, DrugInventoryRespDTO.class)).collect(Collectors.toList());
        return setResultSuccess(inventoryRespDTOList);
    }

    @Override public BaseResponse<DrugInventoryRespDTO> getDrugInventoryPage(Integer currentPageNum, Integer pageSize) {
        LambdaQueryWrapper<DrugInventoryDO> queryWrapper = new LambdaQueryWrapper<>();
        Page<DrugInventoryDO> page = new Page<>(currentPageNum, pageSize);
        Page<DrugInventoryDO> drugInventoryPage = drugInventoryMapper.selectCurrentPage(page, queryWrapper);
        return setResultSuccess(drugInventoryPage);
    }

    @Override public BaseResponse queryDrugInventoryPageByForm() {
        return null;
    }
}